<?php
class Course{

	public function getcourse(){
		$DB = new DB();
		$sql = "SELECT * FROM course";
		return $DB->fetchAll($sql);
	}
	
	public function addCourse($title){
		$DB = new DB();
		$sql = "INSERT INTO `course` VALUES (:id,:title)";
		$field = array(':id' => '',
					   ':title' => $title
					  );	
		return $DB->updateDB($sql,$field);			
	}
	
	public function getCourseById($id){
		$DB = new DB();
		$sql = "SELECT * from course where id='$id'";
		return $DB->fetchRow($sql);
		
	}
	
	public function editCourse($id,$title){
		$DB = new DB();
		$sql = "UPDATE `course` set title=? where id='$id'";
		$field = array($title);
		return $DB->updateDB($sql,$field);	
	}
	
	public function delCourse($id){
		global $db;
		$sql = "delete from `course` where id='$id'";
		return $db->query($sql);		
	}
	
	public function getCs($id){
		$DB = new DB();
		$sql = "select * from `cs` where class_id='$id' order by lesson asc";
		return $DB->fetchAll($sql);
	}
	
	public function editCs($class,$lesson,$field,$value){
		$DB = new DB();
		$sql = "UPDATE `cs` set $field=? where lesson = '$lesson' and class_id = '$class'";
		
		$field = array($value);
		return $DB->updateDB($sql,$field);		
	}
}
?>